package com.keith.jpa.tenant.thread;

import com.alibaba.ttl.threadpool.TtlExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * TenantThreadPoolUtils.java
 * 异步线程上下文处理线程池
 *
 * @author czykeih
 * @version 1.0 2023/10/25
 */
public class TenantThreadPoolUtils {
    public static ExecutorService getThreadPool(int core,int maxSize,int capacity,String name){
        ThreadPoolExecutor executor=new ShowThreadPool(core,maxSize,180, TimeUnit.SECONDS,new ArrayBlockingQueue<>(capacity),new ThreadFactoryBuilder().setNameFormat(name+"-%d").build(),new ThreadPoolExecutor.CallerRunsPolicy());
        return TtlExecutors.getTtlExecutorService(executor);
    }

    public static ExecutorService getThreadPool(int core,int maxSize,String name){
        return getThreadPool(core,maxSize,10000,name);
    }
}
